const path = require("path");

function resolve(dir) {
  return path.join(__dirname, dir);
}
module.exports = {
  // scss 全局配置
  outputDir: "mbb",
  /*输出目录*/
  publicPath: "/",
  /*访问前缀*/
  lintOnSave: false, //关闭Eslint检测
  configureWebpack: {
    name: "有余",
  },
  productionSourceMap: false,
  // 配置全局scss
  css: {
    loaderOptions: {
      scss: {
        additionalData: `@import "src/assets/scss/index.scss";`,
      },
    },
  },
  // 隐藏源码
  chainWebpack: (config) => {
    config.resolve.alias
      .set("@", resolve("src"))
      .set("views", resolve("src/views"))
      .set("assets", resolve("src/assets"))
      .set("common", resolve("src/common"));

    // 配置node-sass
    // const oneOfsMap = config.module.rule("scss").oneOfs.store;
    // oneOfsMap.forEach((item) => {
    //   item
    //     .use("sass-resources-loader")
    //     .loader("sass-resources-loader")
    //     .options({
    //       // 全局scss 导入配置
    //       resources: "src/assets/scss/index.scss",
    //     })
    //     .end();
    // });

    // 优化前端页面的资源加载 配置
    config.plugin("preload").tap(() => [
      {
        rel: "preload",
        fileBlacklist: [/\.map$/, /hot-update\.js$/, /runtime\..*\.js$/],
        include: "initial",
      },
    ]);
    // when there are many pages, it will cause too many meaningless requests
    config.plugins.delete("prefetch");

    // 配置svg的使用
    // 可参考 ： https://blog.csdn.net/qq_26769677/article/details/107475803
    config.plugins.delete("prefetch");
    config.module.rule("svg").exclude.add(resolve("src/config/icons")).end();
    config.module
      .rule("icons")
      .test(/\.svg$/)
      .include.add(resolve("src/config/icons"))
      .end()
      .use("svg-sprite-loader")
      .loader("svg-sprite-loader")
      .options({
        symbolId: "icon-[name]",
      })
      .end();
  },
  // 跨域代理
  devServer: {
    open: true, // 自动打开
    port: 9080, //修改启动的端口号
    // proxy: {
    //     "/": {
    //         target: "http://localhost:1234",
    //         changeOrigin: true,
    //         pathRewrite: {
    //             "^/": "/",
    //         },
    //     },
    // },
  },
};
